import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { MenuState } from '../type'

const menuState: MenuState = {
  isCollapse: false,
  menuList: []
}

const menuSlice = createSlice({
  name: 'menu',
  initialState: menuState,
  reducers: {
    changeCollapse(state: MenuState, { payload }: PayloadAction<boolean>) {
      state.isCollapse = payload
    },
    setRouteMenuList(state: MenuState, { payload }: PayloadAction<Menu.MenuOptions[]>) {
      state.menuList = payload
    }
  }
})

export default menuSlice.reducer
export const { changeCollapse, setRouteMenuList } = menuSlice.actions
